class HelpController < ApplicationController
  before_filter :spam_required, :only=>['add_question','add_subscribe']
  caches_page :enterquestion, :article, :article_show, :show_answer, :faq_answer, :show_article_faq_list, :help_category, :help_categories, :show

  def enterquestion
    if !params[:id] || params[:id] == ""
      render :nothing => true
      return
    end
    @faq = Faq.new(:id => 0, :question => params[:id])
    @faqs = Faq.search(@faq.question)
    render :partial => "faq_result"
  end

  def article
    @article = Article.find(params[:id])
    @category = @article.help_category
    @page_title += " - #{@article.title}"
    render :action => "show"
  end

  def add_question
    load_params_from_session
    
    @email = params[:email]
    @faq = Faq.create(:question => params[:question])
    @faq.add_subscriber(@email)
    render :partial => "faq_sent"
  end

  def add_subscribe
    load_params_from_session

    @email = params[:email]
    id = params[:id]
    @faq = Faq.find(id)
    @faq.add_subscriber(@email)
    render :partial => "faq_sent"
  end

  def article_show
    article = Article.find(params[:id])
    render :partial => "article_show", :locals => { :article => article }
  end

  def show_answer
    faq = Faq.find(params[:id])
    render :partial => "show_answer", :locals => { :faq => faq }
  end

  def faq_answer
    faq = Faq.find(params[:id])
    render :partial => "faq_answer", :locals => { :faq => faq }
  end

  def show_article_faq_list
    @faqs = Article.find(params[:id]).faqs
    render :partial => "faq_list"
  end

  def show_faq_send
    id = params[:id]
    @faq = Faq.find(id)

    render :partial => "faq_send", :locals => { :action => "add_subscribe", :faq => @faq}
  end

  def help_category
    id = params[:id]
    @category = HelpCategory.find(id)

    render :partial => "help_category"
  end

  def show_categories
    @help_categories = HelpCategory.find(:all)
    render :partial => "help_categories"
  end

  def show
    @page_title += " - Hjälp"
    @help_categories = HelpCategory.find(:all)
  end

end
